package com.tcc.task;

import org.testng.Assert;
import org.testng.AssertJUnit;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import com.tcc.qa.test.util.BaseTest;
import com.tcc.qa.test.util.ButtonFinder;
import com.tcc.qa.test.util.MsgFinder;
import com.tcc.qa.test.util.SelectFinder;
public class CategoryStatus extends BaseTest{
	@BeforeMethod
	public void beforeTestMethod(){
		System.out.println("Before Test Method");
	}
	//******************************************************************************************
	@Test(description="Add status",priority=1)
	public void add_Status(){
	getWebDriver().get(super.getTestDomainURL() +"PageServlet?cx=u&pg=papp&tg=Tasks-prefStatus");
		for(int i=1;i<=3;i++){
	ButtonFinder.getButtonByTitle(getWebDriver(), "Add").click();
	getWebDriver().switchTo().alert().sendKeys("Status"+Integer.toString(i));
	getWebDriver().switchTo().alert().accept();
		}
		AssertJUnit.assertEquals(SelectFinder.getSelectText(getWebDriver(), "statuses",2),"Status1");
		AssertJUnit.assertEquals(SelectFinder.getSelectText(getWebDriver(), "statuses",3),"Status2");
		AssertJUnit.assertEquals(SelectFinder.getSelectText(getWebDriver(), "statuses",4),"Status3");
		ButtonFinder.getInputButtonByValue(getWebDriver(), "Save").click();
		Assert.assertEquals(MsgFinder.getMsgDiv(getWebDriver()).getText(), "Status list has been updated.");
		
	}
	//********************************************************************************************
	@Test(description="Check Sort status function",priority=2)
	public void sort_Status(){
		SelectFinder.getSelectOption(getWebDriver(), "statuses", 3).click(); 
	for(int i=0;i<2;i++)
	{
	ButtonFinder.getButtonByTitle(getWebDriver(),"Move Up").click();
	}
	SelectFinder.getSelectOption(getWebDriver(), "statuses", 2).click(); 
	for(int i=0;i<1;i++)
	{
		ButtonFinder.getButtonByTitle(getWebDriver(),"Move Down").click();
	}
	System.out.println("Add status OK!");
	ButtonFinder.getInputButtonByValue(getWebDriver(), "Save").click();
	AssertJUnit.assertEquals(SelectFinder.getSelectText(getWebDriver(), "statuses", 0),"New");
	AssertJUnit.assertEquals(SelectFinder.getSelectText(getWebDriver(), "statuses", 1),"Status3");
	AssertJUnit.assertEquals(SelectFinder.getSelectText(getWebDriver(), "statuses", 2),"Status2");
	AssertJUnit.assertEquals(SelectFinder.getSelectText(getWebDriver(), "statuses", 3),"Status1");
	AssertJUnit.assertEquals(SelectFinder.getSelectText(getWebDriver(), "statuses", 4),"Completed");
	System.out.println("Compare status OK!");
	
	}
	//*****************************************************************************************************

	//***********************Edit "New" and "Complete" Status**********************
	@Test(priority=4,description="Verify Edit status--new and complete")
	public void edit_NewComplete(){
	SelectFinder.getSelectOption(getWebDriver(), "statuses", 0).click(); 
	ButtonFinder.getButtonByTitle(getWebDriver(), "Rename").click();
	AssertJUnit.assertEquals(getWebDriver().switchTo().alert().getText(),"Sorry, 'New' and 'Completed' are system reserved statuses.");
	getWebDriver().switchTo().alert().accept();
	SelectFinder.getSelectOption(getWebDriver(), "statuses", 4).click(); 
	ButtonFinder.getButtonByTitle(getWebDriver(), "Rename").click();
	AssertJUnit.assertEquals(getWebDriver().switchTo().alert().getText(),"Sorry, 'New' and 'Completed' are system reserved statuses.");
	getWebDriver().switchTo().alert().accept();
	System.out.println("Edit test OK!");
		}
	
	//***********************Delete "New" and "Complete Status" **********************
		@Test(priority=4,description="Verify Edit status--new and complete")
		public void delete_NewComplete(){
			
			SelectFinder.getSelectOption(getWebDriver(), "statuses", 0).click(); 
			ButtonFinder.getButtonByTitle(getWebDriver(), "Delete").click();
		AssertJUnit.assertEquals(getWebDriver().switchTo().alert().getText(),"Sorry, 'New' and 'Completed' are system reserved statuses.");
		getWebDriver().switchTo().alert().accept();
		SelectFinder.getSelectOption(getWebDriver(), "statuses", 4).click(); 
		ButtonFinder.getButtonByTitle(getWebDriver(), "Delete").click();
		AssertJUnit.assertEquals(getWebDriver().switchTo().alert().getText(),"Sorry, 'New' and 'Completed' are system reserved statuses.");
		getWebDriver().switchTo().alert().accept();
			}

}
